<script type="text/javascript" language="javascript">

$(function(){
	$('#clients_table').flexigrid({
		url: '<?=site_url("backend/ajax/clients/get")?>',
		dataType: 'json',
		colModel : [
			{display: 'Client Name', name : 'name', width : 180, sortable : true, align: 'left'},
			{display: 'Company Name', name : 'company_name', width : 120, sortable : true, align: 'left'},
			{display: 'Mailing Address', name : 'mailing_address', width : 80, sortable : true, align: 'right', hide: true},
			{display: 'Email Address', name : 'email_address', width : 80, sortable : true, align: 'right', hide: true},
			{display: 'Balance', name : 'balance', width : 130, sortable : true, align: 'left'}
			],
		buttons : [
			{name: 'Add', bclass: 'ui-icon-document', options:{icons:{primary: 'ui-icon-document'}}, onpress : function(){
				$('#client-form')[0].reset();
				$('#client_act').val("add");
				$('#client-dialog-form').dialog('open');
			}},
			{name: 'Edit', bclass: 'ui-icon-pencil', options:{icons:{primary: 'ui-icon-pencil'}}, onpress : function(act, grid){
				$('.trSelected', grid).each(function(index, row) {
					var row_data = $(row).data('rowData');
					var row_id = row_data.id;
					$.getJSON('<?=site_url("/backend/ajax/clients/get/")?>/'+row_id,
						function(data){
							thisClient = data.data[0]; 
							$('#client_act').val("mod");
							$("#client_name").val(thisClient.name);
							$('#client_company_name').val(thisClient.company_name);
							$("#client_email_address").val(thisClient.email_address);
							$("#client_mailing_address").val(thisClient.mailing_address);
							$('#client-dialog-form').dialog('open');
						}
					);
				});
				
			}}/*,
			{name: 'Delete', bclass: 'ui-icon-trash', options:{icons:{primary: 'ui-icon-trash'},create:function(event, btn){
				$(this).easyconfirm({
					locale:{
						title: "Are you sure you want to remove this Client?",
						text: "This action cannot be undone!"
					}
				});
			}}}*/
			],
		searchitems : [
			{display: 'Client Name', name : 'name', isdefault: true},
			{display: 'Company Name', name : 'company_name'}
			],
		sortname: "id",
		sortorder: "asc",
		usepager: true,
		useRp: true,
		rp: 15,
		height: 200,
		themeRoller:true,
		singleSelect:true
	});
});
</script>
